package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author abc
 * @version 1.0  /eduservice/
 * @date 2021/3/17 12:01
 */

@RestController
@RequestMapping("/eduservice/indexfront")
//@CrossOrigin  //解决跨域
public class IndexFrontController {

    //课程注入
    @Autowired
    private EduCourseService courseService;
    //老师注入
    @Autowired
    private EduTeacherService teacherService;
    //查询前8条热门课程(降序） 查询前4条名师 课程 名师的首页接口
    @GetMapping("/index")
    public R index(){
        //查询前8条热门课程(降序
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 4");
        List<EduCourse> eduList = courseService.list(wrapper);
        System.out.println("热门课程"+eduList);

        //查询前4条名师
        QueryWrapper<EduTeacher> wrapper1 = new QueryWrapper<>();
        wrapper1.orderByDesc("id");
        wrapper1.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(wrapper1);
        System.out.println("名师"+teacherList);

        return R.ok().data("eduList",eduList).data("teacherList",teacherList);
    }
}
